import java.util.Arrays;
import java.util.Scanner;



public class Main {
    public static void main(String[] args)
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        PersonSortable[] person=new PersonSortable[n];
        for(int i=0;i<n;i++)
        {
            person[i]=new PersonSortable(sc.next(),sc.nextInt());
        }
        Arrays.sort(person);
        for(int i=0;i<n;i++)
        {
            System.out.println(person[i].toString());
        }
        System.out.println(Arrays.toString(PersonSortable.class.getInterfaces()));
    }

}

class PersonSortable implements Comparable{
    private String name;
    private int age;

    PersonSortable(String name,int age)
    {
        this.name=name;
        this.age=age;

    }

    @Override
    public String toString()
    {
        return this.name+'-'+this.age;
    }

    public int compareTo(Object obj)
    {
        if(obj instanceof PersonSortable) {
            PersonSortable p = (PersonSortable) obj;
            PersonSortable tmp;
            if (!this.name.equals(p.name)) {
                if (this.name.compareTo(p.name)>0) return 1;
                else return -1;

            } else {
                if (this.age > p.age) return 1;
                else return -1;

            }
        }
        return this.compareTo(obj);

    }

}



